// pages/shops/shops.js
const app=getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        query: {},
        shopLis: [],
        page: 1,
        pageSize: 10,
        msg:''
    },
    gotoDts(e){
       console.log(e);
       wx.navigateTo({
         url: '/pages/detail/detail?dts='+JSON.stringify(e.currentTarget.dataset.dts) ,
       
       })
    },
    getShopLis() {
        let {
            page,
            pageSize,
            shopLis
        } = this.data

        wx.request({
            url: `https://www.escook.cn/categories/${this.data.query.id}/shops`,
            method: 'GET',
            data: {
                _page: page,
                _limit: pageSize
            },
            success: (res) => {
                console.log(res);
                const total = res.header['X-Total-Count']
                if (page * pageSize < total || total > 0 && total < pageSize && page === 1) {
                    page++
                    this.setData({
                        shopLis: [...shopLis, ...res.data],
                        page
                    })
                } else {
                    wx.showToast({
                        title: '暂无更多商铺',
                        icon: 'none',
                    })
                }
            }
        })

    },
    onLoad: function (options) {
        console.log(app.globalData);
        this.setData({
            query: options,
            msg:app.globalData.msg
        })
        this.getShopLis();
    },

    onReady: function () {
        wx.setNavigationBarTitle({
            title: this.data.query.name
        })
    },

    onPullDownRefresh: function () {

    },

    onReachBottom: function () {
        // this.getShopLis();
    }
})